package web.security;

import core.entity.User;
import core.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author MG
 * @since 29.04.2014
 */
@Component
public class LoginService implements UserDetailsService {

    UserService userService;
    @Override
    public UserDetails loadUserByUsername(String firstName) throws UsernameNotFoundException {

        User user = userService.findUserByFirstName(firstName);
        if(user != null) {
            return new AppUserDetails(new User());
        }else {
            throw new UsernameNotFoundException("User doesn't exists");
        }
    }
}
